﻿using System;
using System.Web;
using Framework;

namespace Enterprise.Admin.Handle.Download
{
    public partial class Add : AdminBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            object result;
            try
            {
                var file = Request.Files["Filedata"];
                if (file == null)
                {
                    result = (new { state = false, message = "上传文件不能为空！" });
                }
                else
                {
                    var filedata = new HttpPostedFileWrapper(Request.Files["Filedata"]);
                    var name = Fq("CoName").SafeToString();
                    var nameEn = Fq("CoNameEn").SafeToString();
                    var description = Fq("CoDescription").SafeToString();
                    var descriptionEn = Fq("CoDescriptionEn").SafeToString();
                    var language = Fq("CoLanguage").SafeToString();
                    var sorts = Fq("CoSort").SafeToInt();
                    var type = Fq("CoType").SafeToInt();
                    var downloadService = new DownloadService();
                    downloadService.Add(name, nameEn, description, descriptionEn, type, language, sorts, filedata);
                    result = (new { state = true, message = "上传成功！" });
                }

            }
            catch (Exception ex)
            {
                result = (new { state = false, message = ex.Message });
            }
            Response.Write(result.Serialization());
            Response.End();

        }
    }
}